#include "StdAfx.hpp"
#include "MeshRenderingComponent.hpp"
#include "Texture.hpp"
#include "Mesh.hpp"
#include "Engine.hpp"
#include "Material.hpp"


MeshRenderingComponent::MeshRenderingComponent()
: m_Mesh(NULL)
, m_Material(NULL)
{
}

MeshRenderingComponent::~MeshRenderingComponent()
{
	if (m_Material)
		m_Material->Release();
	if (m_Mesh)
		m_Mesh->Release();
}

void MeshRenderingComponent::SetMesh(Mesh *v)
{
	UpdateObjPtr(m_Mesh, v);
}

void MeshRenderingComponent::SetMaterial( Material *v )
{
	UpdateObjPtr(m_Material, v);
}

void MeshRenderingComponent::GetRenderItems( RenderItemVector &outItems )
{
	outItems.clear();
	if (m_Material && m_Mesh)
		outItems.push_back(RENDER_ITEM(0, m_Material->CalcRenderingPasses(), m_Material));
}

void MeshRenderingComponent::RenderGeometry(uint itemId)
{
	if (m_Mesh)
		m_Mesh->Draw();
}

void MeshRenderingComponent::RenderCustom(uint itemId, RENDER_PASS pass, const void *renderContext)
{
}
